{block name=body}
<div class="container content">
    <div class="row">
        <div class="col-sm-12">
            <span class="hidden-xs">{include file='breadcrumbs.tpl'}</span>
            <h1 class="title">{$product_name}</h1>
        </div>
    </div>
    <!-- /.row -->
</div>
<div id="prodtopcont">
    <div class="container">
        <div class="row">
            <div class="col-sm-7 col-md-8">
                {foreach $gallery as $image }
                <div class="image">
                    <img class="img-responsive" src="{$image.gallery_link}" title="{$image.gallery_title}" alt="{$image.gallery_alt_tag}">
                </div>
            </div>
            {/foreach}
            <div class="col-sm-5 col-md-4">
                <form class="form-horizontal" id="product-form" role="form" accept-charset="UTF-8" action="" method="post">
                    <input type="hidden" value="ADDTOCART" name="action" id="action" />
                    <input type="hidden" name="formToken" id="formToken" value="{$token}" />
                    <input type="hidden" value="{$product_object_id}" name="product_id" id="product_id" />
                    <input type="hidden" value="{$listing_parent.listing_object_id}" name="listing_id" id="listing_id" />
                    <div class="prodprice">
                        {if $product_specialprice eq '0.00'}
                        <div style="display:inline;" id="cal-price" value="{$product_price}">{$CURRENCY_SYMBOL}{$product_price|number_format:2:'.':','}</div>
                        <span class="blue gst">{if $product_gst}inc {$TAX_CODE}{else}{$TAX_CODE}-free{/if}</span>
                        {else}
                        <div style="display:inline;" id="cal-price" value="{$product_specialprice}">{$CURRENCY_SYMBOL}{$product_specialprice|number_format:2:'.':','}</div>
                        <!-- <span class="blue gst">{if $product_gst}inc {$TAX_CODE}{else}{$TAX_CODE}-free{/if}</span> -->
                        <div class="small old-price">原价 {$CURRENCY_SYMBOL}{$product_price|number_format:2:'.':','}</div>
                        <div class="special-banner">特价</div>
                        {/if}
                    </div>
                    <div style="display:inline;">
                        <input type="hidden" value="{$product_price}" name="price" id="price" /> </div>
                    <div class="prodoptionsbox">
                        {foreach $attribute as $attr } {if $attr.attr_value}
                        <div class="form-group">
                            <div class="col-sm-12">
                                <label for="address_state_1" class="control-label blue">{$attr.attribute_description}</label>
                                <select id="{urlencode data=$attr.attribute_name}" name="attr[{$attr.attribute_id}]" class='form-control modifier required'>
                                    <option value="" price="0" instock="0" weight="0" width="0" height="0" length="0" name="">请选择
                                    </option>
                                    {foreach $attr.attr_value as $value }
                                    <option value="{$value.attr_value_id}" price="{if $product_specialprice neq '0.00'}{$value.attr_value_specialprice}{else}{$value.attr_value_price}{/if}" instock="{$value.attr_value_instock}" weight="{$value.attr_value_weight}" width="{$value.attr_value_width}" height="{$value.attr_value_height}" length="{$value.attr_value_length}" name="{urlencode data=$value.attr_value_name}">{$value.attr_value_name}
                                    </option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {/if} {/foreach} {if $product_instock}
                        <div class="form-group">
                            <div class="col-sm-12">
                                <label for="address_state_1" class="control-label blue">数量</label>
                                <select name="quantity" id="quantity" class="form-control">
                                    {for $foo=1 to 12}
                                    <option value="{$foo}">{$foo}</option>
                                    {/for}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <button type="submit" class="cart"><span>加入购物车</span></button>
                                <div style="display:inline;color:#ff0000" id="error-text"></div>
                            </div>
                        </div>
                        {else}
                        <div class="text-center">
                            <div class="text-danger">缺货</div>
                            <small>请联系 <a title="Click to call" href="tel:{$PHONE}">{$PHONE}</a> 获取更多信息。</small>
                        </div>
                        {/if}
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col-sm-12">
            {$product_content1}
        </div>
    </div>
</div>
{if isset($associate1)}
<div id="related">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <span class="blue reltitle">相关产品</span>
            </div>
            <div class="col-sm-12" id="prodcontainer">
                {if isset($associate1)}
                <div class="citem {$associate1.listing_name}">
                    <a href="{$parenturl}/{$associate1.cache_url}">
                        <img src="{if $associate1.gallery_link neq ''}{$associate1.gallery_link}{else}/images/no-image-available.jpg{/if}" alt="{$associate1.gallery_caption}" title="{$associate1.gallery_title}" class="img-responsive">
                        <div class="prodinfo">
                            <div class="prodname">{$associate1.product_name}</div>
                            {if $associate1.product_specialprice gt 0}
                            <div class="prodprice">{$CURRENCY_SYMBOL}{$associate1.product_specialprice}
                                <div class="small">原价 {$CURRENCY_SYMBOL}{$associate1.product_price}</div>
                            </div>
                            <div class="special-banner small">特价</div>
                            {else}
                            <div class="prodprice">{$CURRENCY_SYMBOL}{$associate1.product_price}
                            </div>
                            {/if}
                        </div>
                    </a>
                </div>
                {/if} {if isset($associate2)}
                <div class="citem {$associate2.listing_name}">
                    <a href="{$parenturl}/{$associate2.cache_url}">
                        <img src="{if $associate2.gallery_link neq ''}{$associate2.gallery_link}{else}/images/no-image-available.jpg{/if}" alt="{$associate2.gallery_caption}" title="{$associate2.gallery_title}" class="img-responsive">
                        <div class="prodinfo">
                            <div class="prodname">{$associate2.product_name}</div>
                            {if $associate2.product_specialprice gt 0}
                            <div class="prodprice">{$CURRENCY_SYMBOL}{$associate2.product_specialprice}
                                <div class="small">原价 {$CURRENCY_SYMBOL}{$associate2.product_price}</div>
                            </div>
                            <div class="special-banner small">特价</div>
                            {else}
                            <div class="prodprice">{$CURRENCY_SYMBOL}{$associate2.product_price}
                            </div>
                            {/if}
                        </div>
                    </a>
                </div>
                {/if} {if isset($associate3)}
                <div class="citem {$associate3.listing_name}">
                    <a href="{$parenturl}/{$associate3.cache_url}">
                        <img src="{if $associate3.gallery_link neq ''}{$associate3.gallery_link}{else}/images/no-image-available.jpg{/if}" alt="{$associate3.gallery_caption}" title="{$associate3.gallery_title}" class="img-responsive">
                        <div class="prodinfo">
                            <div class="prodname">{$associate3.product_name}</div>
                            {if $associate3.product_specialprice gt 0}
                            <div class="prodprice">{$CURRENCY_SYMBOL}{$associate3.product_specialprice}
                                <div class="small">原价 {$CURRENCY_SYMBOL}{$associate3.product_price}</div>
                            </div>
                            <div class="special-banner small">特价</div>
                            {else}
                            <div class="prodprice">{$CURRENCY_SYMBOL}{$associate3.product_price}
                            </div>
                            {/if}
                        </div>
                    </a>
                </div>
                {/if}
            </div>
            <div class="col-sm-6 col-sm-offset-3">
                <button type="button" onclick="window.location.assign('/products')" class="enquire"><span>查看所有商品</span></button>
            </div>
        </div>
    </div>
</div>
{/if} 
{include file='helpblock.tpl'}
{/block}

{block name=tail}
<script type="text/javascript">
$(document).ready(function() {
    $('select').selectBoxIt();

    $('#product-form').validate({
        onkeyup: false,
        onclick: false
    });

    var attributes = [];

{if $attribute}
{foreach $attribute as $attr }
    var {urlencode data=$attr.attribute_name} = getParameterByName('{urlencode data=$attr.attribute_name}');
    attributes.push( getParameterByName('{urlencode data=$attr.attribute_name}') );
    $("#{urlencode data=$attr.attribute_name} option[name*='"+ {urlencode data=$attr.attribute_name} +"']").attr("selected", "selected"); 
{/foreach}
{/if}

    calculatePrice();

    // ga('ec:addProduct', {
    //     'id': '{$product_object_id}',
    //     'name': '{$product_name}',
    //     'category': '{$product_FullCategoryName}',
    //     'brand': '{$product_brand}',
    //     'variant': attributes.join('/')
    // });
    // ga('ec:setAction', 'detail');
    // ga('oldTracker.ec:addProduct', {
    //     'id': '{$product_object_id}',
    //     'name': '{$product_name}',
    //     'category': '{$product_FullCategoryName}',
    //     'brand': '{$product_brand}',
    //     'variant': attributes.join('/')
    // });
    // ga('oldTracker.ec:setAction', 'detail');
});

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
{/block}
